/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SampleHost;
import java.io.File;
import java.io.FileInputStream;

/**
 *
 * @author Owner
 */
public class Main {
    public static PortWriter portWriter;
    public static PortReader portReader;
/*
    public static void setup(String portName) throws Exception {
        PortObject port = new PortObject(portName);
        portWriter = new PortWriter(port);
        portReader = new PortReader(port);
    }

    public static void startTransaction(int imageSize) throws Exception {
        portWriter.writeWord(0xdeadc0de);
        portWriter.writeWord(imageSize);
        int response = portReader.readWord();
        if (0x900df00d == response) {
            System.out.println("Expected response received");
        }
    }

    public static void transmitFile(String pathName) throws Exception {
        File file = new File(pathName);
        startTransaction((int)file.length());
        FileInputStream stream = new FileInputStream(file);
        portWriter.write(stream);
    }

    public static void main(String[] args) {
        if (2 > args.length) {
            System.out.println("Specify COM port number");
        }
        else {
            try {
                setup(args[0]);
                transmitFile(args[1]);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        System.exit(0);
    }
*/
    public static void main(String[] args) {
        try {
            DeviceLink link = new DeviceLink("COM2");
            //byte b = link.readByte(DeviceLink.BLOCKFOREVER);
            //byte b = link.readByte(DeviceLink.BLOCKFOREVER);
            int b = link.readWord(DeviceLink.BLOCKFOREVER);
            System.out.println(String.valueOf(b));
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        System.exit(0);
    }
}
